package com.whiteape.book.core.manager;


import com.whiteape.book.core.page.PageMode;
import com.whiteape.book.core.page.PageStyle;
import com.whiteape.book.core.page.PageStyleNew;
import com.whiteape.book.core.page.PageTextIntervalMode;
import com.whiteape.book.model.dto.AdInfoBean;
import com.whiteape.book.model.type.MediaType;
import com.whiteape.book.utils.GsonUtils;
import com.whiteape.book.utils.ScreenUtils;
import com.whiteape.book.utils.SharedPreUtils;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by newbiechen on 17-5-17.
 * 阅读器的配置管理
 */

public class ReadSettingManager {
    /*************实在想不出什么好记的命名方式。。******************/
    public static final int READ_BG_DEFAULT = 0;
    public static final int READ_BG_1 = 1;
    public static final int READ_BG_2 = 2;
    public static final int READ_BG_3 = 3;
    public static final int READ_BG_4 = 4;
    public static final int NIGHT_MODE = 5;

    public static final int READ_COLOR_TYPE_BG = 0;
    public static final int READ_COLOR_TYPE_BG_PIC = 1;
    public static final int READ_COLOR_TYPE_FG = 2;

    public static final int COLLECTION_ORDER_TYPE_LAST_READ_DESC = 0;
    public static final int COLLECTION_ORDER_TYPE_LAST_READ_ASC = 1;
    public static final int COLLECTION_ORDER_TYPE_TITLE_ASC = 2;
    public static final int COLLECTION_ORDER_TYPE_TITLE_DESC = 3;

    public static final int READ_MARGIN_TYPE_LEFT = 0;
    public static final int READ_MARGIN_TYPE_TOP = 1;
    public static final int READ_MARGIN_TYPE_RIGHT = 2;
    public static final int READ_MARGIN_TYPE_BOTTOM = 3;
    //段落间距
    public static final int READ_MARGIN_TYPE_PARA_INTERVAL = 4;
    //行间距
    public static final int READ_MARGIN_TYPE_LINE_INTERVAL = 5;
    public static final int READ_MARGIN_TYPE_TIP_LEFT = 6;
    public static final int READ_MARGIN_TYPE_TIP_TOP = 7;
    public static final int READ_MARGIN_TYPE_TIP_RIGHT = 8;
    public static final int READ_MARGIN_TYPE_TIP_BOTTOM = 9;

    public static final int READ_OTHER_SETTING_HIDE_STATUS_BAR = 0;
    public static final int READ_OTHER_SETTING_HIDE_NAV_BAR = 1;
    public static final int READ_OTHER_SETTING_FULLSCREEN_CLICK_TO_CHANGE_PAGE = 2;
    public static final int READ_OTHER_SETTING_VOLUME_TO_CHANGE_PAGE = 3;
    public static final int READ_OTHER_SETTING_SHOW_TIME = 4;
    public static final int READ_OTHER_SETTING_SHOW_BATTERY = 5;
    public static final int READ_OTHER_SETTING_SHOW_CHAPTER_TITLE = 6;
    public static final int READ_OTHER_SETTING_SHOW_PAGE_PROGRESS = 7;
    public static final int READ_OTHER_SETTING_KEEP_SCREEN_ON = 8;
    public static final int READ_OTHER_SETTING_SHOW_CATALOG_PROGRESS = 9;

    public static final String SHARED_READ_BG = "shared_read_bg";
    public static final String SHARED_READ_PAGE_STYLE = "shared_read_page_style";
    public static final String SHARED_READ_PAGE_STYLE_ALL = "shared_read_page_style_all";
    public static final String SHARED_READ_BRIGHTNESS = "shared_read_brightness";
    public static final String SHARED_READ_IS_BRIGHTNESS_AUTO = "shared_read_is_brightness_auto";
    public static final String SHARED_READ_TEXT_SIZE = "shared_read_text_size";
    public static final String SHARED_READ_IS_TEXT_DEFAULT = "shared_read_text_default";
    public static final String SHARED_READ_PAGE_MODE = "shared_read_mode";
    public static final String SHARED_READ_NIGHT_MODE = "shared_night_mode";
    public static final String SHARED_READ_VOLUME_TURN_PAGE = "shared_read_volume_turn_page";
    public static final String SHARED_READ_FULL_SCREEN = "shared_read_full_screen";
    public static final String SHARED_READ_CONVERT_TYPE = "shared_read_convert_type";
    public static final String SHARED_READ_TYPEFACE = "shared_read_typeface_file_path";
    public static final String SHARED_READ_SPEED = "shared_auto_read_speed";
    public static final String SHARED_LAST_SHARED_TIME = "shared_last_shared_time";
    public static final String SHARED_AGREE_PROTOCOL = "shared_agree_protocol";
    public static final String SHARED_SOURCE_VERSION_CODE = "shared_source_version_code";
    public static final String HOME_PAGE_SITE_HOST_URL = "homepage_site_host_url_";
    public static final String CATEGORY_INDEX_INITED = "category_index_inited";
    public static final String SHARED_READ_TEXT_USE_FANTI = "shared_read_text_use_fanti";
    public static final String SHARED_READ_TEXT_INTERVAL = "shared_read_text_interval";
    public static final String SHARED_READ_TEXT_BOLD = "shared_read_text_bold";
    public static final String SHARED_TTS_SPEED = "shared_tts_speed";
    public static final String COLLECTION_CHANNEL_ORDER = "shared_channel_order";
    public static final String COLLECTION_LIST_OR_GRID = "shared_list_or_grid";
    public static final String COLLECTION_ORDER_TYPE = "shared_coll_order_type";
    public static final String READ_BG_COLORS = "shared_read_bg_colors";
    public static final String READ_BG_PICS = "shared_read_bg_pics";
    public static final String READ_FG_COLORS = "shared_read_fg_colors";
    public static final String READ_COLORS_INITED = "shared_read_colors_inited";
    public static final String READ_PARA_START_SPACES_NUM = "shared_read_para_start_spaces_num";
    public static final String READ_MARGIN = "shared_read_margin";
    public static final String READ_OTHER_SETTINGS = "shared_other_settings";
    public static final String READ_SITE_CATEGORY_TYPE = "shared_site_category_type";
    public static final String SEARCH_OPTIONS_EXACT = "shared_search_options_exact";
    public static final String SEARCH_HISTORY = "shared_search_history";
    public static final String COLL_MEDIA_AUTO_UPDATE_CATALOG = "shared_coll_media_auto_update_catalog";
    public static final String BACKUP_USE_WEB_DAV = "shared_use_web_dav";
    public static final String WEB_DAV_URL = "shared_web_dav_url";
    public static final String WEB_DAV_ACCOUNT = "shared_web_dav_account";
    public static final String WEB_DAV_PASSWORD = "shared_web_dav_password";
    public static final String OPEN_APP_AUTO_SHELF = "shared_open_app_auto_shelf";
    public static final String USE_VOLUME_TO_TURN_PAGE = "sp_use_volume_key";
    public static final String FULL_SCREEN_NEXT_PAGE = "sp_full_screen_page_next";
    public static final String KEEP_SCREEN_ON_WHEN_READING = "sp_keep_screen_on";
    public static final String MIGRATE_AT_VERSION_1_1_2 = "sp_migrate_112";
    public static final String LAST_AD_DOWNLOAD_ID = "sp_last_ad_download_id";
    public static final String AD_ENABLED = "sp_ad_enabled";
    public static final String AD_INFO = "sp_info";
    public static final String UMENG_ID = "sp_umeng_id";
    public static final String README_INIT = "sp_readme_init";

    private static volatile ReadSettingManager sInstance;

    private SharedPreUtils sharedPreUtils;

    public static ReadSettingManager getInstance() {
        if (sInstance == null) {
            synchronized (ReadSettingManager.class) {
                if (sInstance == null) {
                    sInstance = new ReadSettingManager();
                }
            }
        }
        return sInstance;
    }

    private ReadSettingManager() {
        sharedPreUtils = SharedPreUtils.getInstance();
    }

    public void setPageStyle(PageStyle pageStyle) {
        sharedPreUtils.putInt(SHARED_READ_BG, pageStyle.ordinal());
    }

    public void setPageStyleNew(PageStyleNew pageStyle) {
        sharedPreUtils.putString(SHARED_READ_PAGE_STYLE, pageStyle.toString());
    }

    private void initColorsForFirstTime() {
        String bgColorStr = "#CEC29C;#CCEBCC;#AAAAAA;#D1CEC5;#001C27";
        String fgColorStr = "#2C2C2C;#2F332D;#92918C;#383429;#627176";

        ReadSettingManager.getInstance().addReadColors(ReadSettingManager.READ_COLOR_TYPE_BG, bgColorStr);
        ReadSettingManager.getInstance().addReadColors(ReadSettingManager.READ_COLOR_TYPE_FG, fgColorStr);

        String[] bgArr = bgColorStr.split(";");
        String[] fgArr = fgColorStr.split(";");
        List<PageStyleNew> pageStyleNewList = new ArrayList<>();
        for (int i = 0; i < bgArr.length; i++) {
            pageStyleNewList.add(new PageStyleNew(bgArr[i], fgArr[i]));
        }
        ReadSettingManager.getInstance().setPageStyleAll(pageStyleNewList);
    }

    private void initStyles() {
        if (!ReadSettingManager.getInstance().isReadColorsInited()) {
            initColorsForFirstTime();
            ReadSettingManager.getInstance().setReadColorsInited(true);
        }
    }

    public List<PageStyleNew> getPageStyleAll() {
        initStyles();
        String str = sharedPreUtils.getString(SHARED_READ_PAGE_STYLE_ALL);
        List<PageStyleNew> pageStyleNewList = new ArrayList<>();
        String[] pageStyleArr = str.split(";");
        for (String pageStyleStr : pageStyleArr) {
            String[] pageStyleNewArr = pageStyleStr.split(",");
            pageStyleNewList.add(new PageStyleNew(pageStyleNewArr[0], pageStyleNewArr[1]));
        }
        return pageStyleNewList;
    }


    public void setPageStyleAll(List<PageStyleNew> list) {
        StringBuilder sb = new StringBuilder();
        for (PageStyleNew pageStyleNew : list) {
            sb.append(pageStyleNew.getBgColor())
                    .append(",")
                    .append(pageStyleNew.getFontColor())
                    .append(";");
        }
        String str = sb.toString().substring(0, sb.length() - 1);
        sharedPreUtils.putString(SHARED_READ_PAGE_STYLE_ALL, str);
    }

    public void setBrightness(int progress) {
        sharedPreUtils.putInt(SHARED_READ_BRIGHTNESS, progress);
    }

    public void setAutoBrightness(boolean isAuto) {
        sharedPreUtils.putBoolean(SHARED_READ_IS_BRIGHTNESS_AUTO, isAuto);
    }

    public void setDefaultTextSize(boolean isDefault) {
        sharedPreUtils.putBoolean(SHARED_READ_IS_TEXT_DEFAULT, isDefault);
    }

    public void setTextSize(int textSize) {
        sharedPreUtils.putInt(SHARED_READ_TEXT_SIZE, textSize);
    }

    public void setTypeface(String path) {
        sharedPreUtils.putString(SHARED_READ_TYPEFACE, path);
    }

    public String getTypeface() {
        return sharedPreUtils.getString(SHARED_READ_TYPEFACE);
    }

    public void setPageMode(PageMode mode) {
        sharedPreUtils.putInt(SHARED_READ_PAGE_MODE, mode.ordinal());
    }

    public void setNightMode(boolean isNight) {
        sharedPreUtils.putBoolean(SHARED_READ_NIGHT_MODE, isNight);
    }

    public int getBrightness() {
        return sharedPreUtils.getInt(SHARED_READ_BRIGHTNESS, 40);
    }

    public boolean isBrightnessAuto() {
        return sharedPreUtils.getBoolean(SHARED_READ_IS_BRIGHTNESS_AUTO, false);
    }

    public int getTextSize() {
        return sharedPreUtils.getInt(SHARED_READ_TEXT_SIZE, ScreenUtils.spToPx(18));
    }

    public boolean isDefaultTextSize() {
        return sharedPreUtils.getBoolean(SHARED_READ_IS_TEXT_DEFAULT, false);
    }

    public PageMode getPageMode() {
        int mode = sharedPreUtils.getInt(SHARED_READ_PAGE_MODE, PageMode.SIMULATION.ordinal());
        return PageMode.values()[mode];
    }

    public PageStyle getPageStyle() {
        int style = sharedPreUtils.getInt(SHARED_READ_BG, PageStyle.BG_0.ordinal());
        return PageStyle.values()[style];
    }

    public PageStyleNew getPageStyleNew() {
        String style = sharedPreUtils.getString(SHARED_READ_PAGE_STYLE);
        if (StringUtils.isEmpty(style)) {
            style = "#CEC29C;#2C2C2C";
        }
        String[] colors = style.split(";");
        return new PageStyleNew(colors[0], colors[1]);
    }

    public boolean isNightMode() {
        return sharedPreUtils.getBoolean(SHARED_READ_NIGHT_MODE, false);
    }

    public void setVolumeTurnPage(boolean isTurn) {
        sharedPreUtils.putBoolean(SHARED_READ_VOLUME_TURN_PAGE, isTurn);
    }

    public boolean isVolumeTurnPage() {
        return sharedPreUtils.getBoolean(SHARED_READ_VOLUME_TURN_PAGE, false);
    }

    public void setFullScreen(boolean isFullScreen) {
        sharedPreUtils.putBoolean(SHARED_READ_FULL_SCREEN, isFullScreen);
    }

    public boolean isFullScreen() {
        return sharedPreUtils.getBoolean(SHARED_READ_FULL_SCREEN, false);
    }

    public void setConvertType(int convertType) {
        sharedPreUtils.putInt(SHARED_READ_CONVERT_TYPE, convertType);
    }

    public int getConvertType() {
        return sharedPreUtils.getInt(SHARED_READ_CONVERT_TYPE, 0);
    }

    public int getAutoReadSpeed() {
        return sharedPreUtils.getInt(SHARED_READ_SPEED, 5);
    }

    public void setAutoReadSpeed(int speed) {
        sharedPreUtils.putInt(SHARED_READ_SPEED, speed);
    }

    public void setLastSharedTime(long time) {
        sharedPreUtils.putLong(SHARED_LAST_SHARED_TIME, time);
    }

    public long getLastSharedTime() {
        return sharedPreUtils.getLong(SHARED_LAST_SHARED_TIME, 0L);
    }

    public boolean getIfAgreedProtocol() {
        return sharedPreUtils.getBoolean(SHARED_AGREE_PROTOCOL, false);
    }

    public void setIfAgreedProtocol(boolean agree) {
        sharedPreUtils.putBoolean(SHARED_AGREE_PROTOCOL, agree);

    }

    public int getSiteSourceVersionCode() {
        return sharedPreUtils.getInt(SHARED_SOURCE_VERSION_CODE, 0);
    }

    public void setSiteSourceVersionCode(int versionCode) {
        sharedPreUtils.putInt(SHARED_SOURCE_VERSION_CODE, versionCode);

    }

    public String getHomepageSiteHostUrl(int mediaType) {
        return sharedPreUtils.getString(HOME_PAGE_SITE_HOST_URL + mediaType);
    }

    public void setHomePageSiteHostUrl(int mediaType, String url) {
        sharedPreUtils.putString(HOME_PAGE_SITE_HOST_URL + mediaType, url);
    }

    public boolean getIfCategoryIndexInited() {
        return sharedPreUtils.getBoolean(CATEGORY_INDEX_INITED, false);
    }

    public void setCategoryIndexInited(boolean flag) {
        sharedPreUtils.putBoolean(CATEGORY_INDEX_INITED, flag);
    }

    public void setFanti(boolean isFanti) {
        sharedPreUtils.putBoolean(SHARED_READ_TEXT_USE_FANTI, isFanti);
    }

    public boolean getFanti() {
        return sharedPreUtils.getBoolean(SHARED_READ_TEXT_USE_FANTI, false);
    }

    public void setSharedReadTextInterval(int textIntervalType) {
        sharedPreUtils.putInt(SHARED_READ_TEXT_INTERVAL, textIntervalType);
    }

    public int getReadTextInterval() {
        return sharedPreUtils.getInt(SHARED_READ_TEXT_INTERVAL, PageTextIntervalMode.MODE_NORMAL);
    }

    public boolean getBold() {
        return sharedPreUtils.getBoolean(SHARED_READ_TEXT_BOLD, false);
    }

    public void setBold(boolean bold) {
        sharedPreUtils.putBoolean(SHARED_READ_TEXT_BOLD, bold);
    }

    public void setTTSSpeed(float speed) {
        sharedPreUtils.putFloat(SHARED_TTS_SPEED, speed);
    }

    public float getTTSSpeed() {
        return sharedPreUtils.getFloat(SHARED_TTS_SPEED, 1.0f);
    }

    public void setListOrGrid(int mediaType, boolean isList) {
        sharedPreUtils.putBoolean(COLLECTION_LIST_OR_GRID + "" + mediaType, isList);
    }

    public boolean getListOrGrid(int mediaType) {
        return sharedPreUtils.getBoolean(COLLECTION_LIST_OR_GRID + "" + mediaType, true);
    }

    public void setChannelOrder(List<Integer> orderList) {
        String order = StringUtils.join(orderList, ";");
        sharedPreUtils.putString(COLLECTION_CHANNEL_ORDER, order);
    }

    public List<Integer> getChannelOrder() {
        String order = sharedPreUtils.getString(COLLECTION_CHANNEL_ORDER);
        if (StringUtils.isEmpty(order)) {
            return new ArrayList<>();
        }
        String[] orderArr = order.split(";");
        List<Integer> orderList = new ArrayList<>();
        for (String str : orderArr) {
            orderList.add(Integer.parseInt(str));
        }
        return orderList;
    }

    public List<String> getReadColors(int type) {
        List<String> bgColorList = new ArrayList<>();
        String key = READ_BG_COLORS;
        if (type != READ_COLOR_TYPE_BG) {
            key = type == READ_COLOR_TYPE_BG_PIC ? READ_BG_PICS : READ_FG_COLORS;
        }
        String bgColorString = sharedPreUtils.getString(key);
        if (StringUtils.isEmpty(bgColorString)) {
            return bgColorList;
        }
        String[] colorArr = bgColorString.split(";");
        Collections.addAll(bgColorList, colorArr);
        return bgColorList;
    }

    public void addReadColors(int type, String colorStr) {
        String key = READ_BG_COLORS;
        if (type != READ_COLOR_TYPE_BG) {
            key = type == READ_COLOR_TYPE_BG_PIC ? READ_BG_PICS : READ_FG_COLORS;
        }
        String colorsNow = sharedPreUtils.getString(key);
        String colorsNew = StringUtils.isEmpty(colorsNow) ? colorStr.trim() : colorsNow + ";" + colorStr.trim();
        sharedPreUtils.putString(key, colorsNew);
    }

    public void setReadColors(int type, List<String> colorList) {
        String key = READ_BG_COLORS;
        if (type != READ_COLOR_TYPE_BG) {
            key = type == READ_COLOR_TYPE_BG_PIC ? READ_BG_PICS : READ_FG_COLORS;
        }
        StringBuilder sb = new StringBuilder();
        for (String str : colorList) {
            sb.append(str).append(";");
        }
        sharedPreUtils.putString(key, sb.toString().substring(0, sb.length() - 1));


    }

    public void setReadColorsInited(boolean inited) {
        sharedPreUtils.putBoolean(READ_COLORS_INITED, inited);
    }

    public boolean isReadColorsInited() {
        return sharedPreUtils.getBoolean(READ_COLORS_INITED, false);
    }

    public void setReadParaStartSpacesNum(int num) {
        if (num < 0 || num > 4) {
            return;
        }
        sharedPreUtils.putInt(READ_PARA_START_SPACES_NUM, num);
    }

    public int getReadParaStartSpacesNum() {
        return sharedPreUtils.getInt(READ_PARA_START_SPACES_NUM, 2);
    }

    public void setReadMargin(int type, int margin) {
//        if (type < 0 || type > 5) {
//            return;
//        }
        String key = READ_MARGIN + "_" + type;
        sharedPreUtils.putInt(key, margin);

    }

    public int getReadMargin(int type) {
//        if (type < 0 || type > 5) {
//            return 0;
//        }
        String key = READ_MARGIN + "_" + type;
        int defaultValue = 0;
        switch (type) {
            case READ_MARGIN_TYPE_LEFT:
                defaultValue = 15;
                break;
            case READ_MARGIN_TYPE_TOP:
                defaultValue = 15;
                break;
            case READ_MARGIN_TYPE_RIGHT:
                defaultValue = 15;
                break;
            case READ_MARGIN_TYPE_BOTTOM:
                defaultValue = 5;
                break;
            case READ_MARGIN_TYPE_PARA_INTERVAL:
                defaultValue = 18;
                break;
            case READ_MARGIN_TYPE_LINE_INTERVAL:
                defaultValue = 9;
                break;
            case READ_MARGIN_TYPE_TIP_LEFT:
                defaultValue = 8;
                break;
            case READ_MARGIN_TYPE_TIP_TOP:
                defaultValue = 5;
                break;
            case READ_MARGIN_TYPE_TIP_RIGHT:
                defaultValue = 15;
                break;
            case READ_MARGIN_TYPE_TIP_BOTTOM:
                defaultValue = 3;
                break;
        }
        return sharedPreUtils.getInt(key, defaultValue);
    }

    public boolean getReadOtherSettings(int type) {
        if (type == READ_OTHER_SETTING_KEEP_SCREEN_ON) {
            return getKeepScreenOnWhenReading();
        } else if (type == READ_OTHER_SETTING_FULLSCREEN_CLICK_TO_CHANGE_PAGE) {
            return getFullScreenTurnNextPage();
        } else if (type == READ_OTHER_SETTING_VOLUME_TO_CHANGE_PAGE) {
            return getUseVolumeToTurnPage();
        }
        //初始化,除了导航栏不隐藏，其他都是true
        boolean defaultValue = true;
        if (type == READ_OTHER_SETTING_HIDE_NAV_BAR) {
            defaultValue = false;
        }
        String key = READ_OTHER_SETTINGS + "_" + type;
        return sharedPreUtils.getBoolean(key, defaultValue);
    }

    public void setReadOtherSettings(int type, boolean value) {
        if (type == READ_OTHER_SETTING_KEEP_SCREEN_ON) {
            setKeepScreenOnWhenReading(value);
            return;
        } else if (type == READ_OTHER_SETTING_FULLSCREEN_CLICK_TO_CHANGE_PAGE) {
            setFullScreenTurnNextPage(value);
            return;
        } else if (type == READ_OTHER_SETTING_VOLUME_TO_CHANGE_PAGE) {
            setUseVolumeToTurnPage(value);
            return;
        }
        String key = READ_OTHER_SETTINGS + "_" + type;
        sharedPreUtils.putBoolean(key, value);
    }

    public void setReadSiteCategoryType(int type) {
        sharedPreUtils.putInt(READ_SITE_CATEGORY_TYPE, type);
    }

    public int getReadSiteCategoryType() {
        return sharedPreUtils.getInt(READ_SITE_CATEGORY_TYPE, MediaType.MEDIA_TYPE_NOVEL);
    }

    public void setSearchOptionsExact(boolean exact) {
        sharedPreUtils.putBoolean(SEARCH_OPTIONS_EXACT, exact);
    }

    public boolean getSearchOptionsExact() {
        return sharedPreUtils.getBoolean(SEARCH_OPTIONS_EXACT, false);
    }

    public void setSearchHistory(String history) {
        sharedPreUtils.putString(SEARCH_HISTORY, history);
    }

    public void addSearchHistory(String word) {
        List<String> historyList = getSearchHistory();
        if (historyList.contains(word)) {
            return;
        }
        if (historyList.size() >= 10) {
            historyList.remove(historyList.size() - 1);
        }
        historyList.add(0, word);

        StringBuffer sb = new StringBuffer();
        for (String str : historyList) {
            sb.append(str).append(";");
        }
        String historyStr = sb.toString();
        historyStr = historyStr.substring(0, historyStr.length() - 1);
        setSearchHistory(historyStr);
    }

    public List<String> getSearchHistory() {
        String history = sharedPreUtils.getString(SEARCH_HISTORY);
        String[] arr = history.split(";");
        return new ArrayList<>(Arrays.asList(arr));
    }

    public boolean getCollMediaAutoUpdateCatalog() {
        return sharedPreUtils.getBoolean(COLL_MEDIA_AUTO_UPDATE_CATALOG, false);
    }

    public void setCollMediaAutoUpdateCatalog(boolean autoUpdateCatalog) {
        sharedPreUtils.putBoolean(COLL_MEDIA_AUTO_UPDATE_CATALOG, autoUpdateCatalog);
    }

    public String getWebDavUrl() {
        return sharedPreUtils.getString(WEB_DAV_URL);
    }

    public void setWebDavUrl(String webDavUrl) {
        sharedPreUtils.putString(WEB_DAV_URL, webDavUrl);
    }

    public String getWebDavAccount() {
        return sharedPreUtils.getString(WEB_DAV_ACCOUNT);
    }

    public void setWebDavAccount(String webDavAccount) {
        sharedPreUtils.putString(WEB_DAV_ACCOUNT, webDavAccount);
    }

    public String getWebDavPassword() {
        return sharedPreUtils.getString(WEB_DAV_PASSWORD);
    }

    public void setWebDavPassword(String webDavPassword) {
        sharedPreUtils.putString(WEB_DAV_PASSWORD, webDavPassword);
    }

    public int getCollOrderType() {
        String value = sharedPreUtils.getString(COLLECTION_ORDER_TYPE);
        if (StringUtils.isEmpty(value)) {
            return COLLECTION_ORDER_TYPE_LAST_READ_DESC;
        }
        return Integer.parseInt(value);
    }

    //注意 int -> string，主要ListPreference中的0，1，2都是string格式存储的
    public void setCollOrderType(int type) {
        sharedPreUtils.putString(COLLECTION_ORDER_TYPE, type + "");
    }

    public boolean getOpenAppAutoShelf() {
        return sharedPreUtils.getBoolean(OPEN_APP_AUTO_SHELF, false);
    }

    public void setOpenAppAutoShelf(boolean auto) {
        sharedPreUtils.putBoolean(OPEN_APP_AUTO_SHELF, auto);
    }

    //不用set方法，在SettingFragment中的Preference中设定
    public boolean getBackupUseWebDav() {
        return sharedPreUtils.getBoolean(BACKUP_USE_WEB_DAV, false);
    }

    public boolean getUseVolumeToTurnPage() {
        return sharedPreUtils.getBoolean(USE_VOLUME_TO_TURN_PAGE, false);
    }

    public void setUseVolumeToTurnPage(boolean value) {
        sharedPreUtils.putBoolean(USE_VOLUME_TO_TURN_PAGE, value);
    }

    public boolean getFullScreenTurnNextPage() {
        return sharedPreUtils.getBoolean(FULL_SCREEN_NEXT_PAGE, false);
    }

    public void setFullScreenTurnNextPage(boolean value) {
        sharedPreUtils.putBoolean(FULL_SCREEN_NEXT_PAGE, value);
    }

    public boolean getKeepScreenOnWhenReading() {
        return sharedPreUtils.getBoolean(KEEP_SCREEN_ON_WHEN_READING, false);
    }

    public void setKeepScreenOnWhenReading(boolean value) {
        sharedPreUtils.putBoolean(KEEP_SCREEN_ON_WHEN_READING, value);
    }

    public boolean getMigrateAtVersion112() {
        return sharedPreUtils.getBoolean(MIGRATE_AT_VERSION_1_1_2, false);
    }

    public void setMigrateAtVersion112(boolean value) {
        sharedPreUtils.putBoolean(MIGRATE_AT_VERSION_1_1_2, value);
    }

    public long getLastAdDownloadId() {
        return sharedPreUtils.getLong(LAST_AD_DOWNLOAD_ID, 0);
    }

    public void setLastAdDownloadId(long id) {
        sharedPreUtils.putLong(LAST_AD_DOWNLOAD_ID, id);
    }

    public boolean getAdEnabled() {
        return sharedPreUtils.getBoolean(AD_ENABLED, false);
    }

    public void setAdEnabled(boolean value) {
        sharedPreUtils.putBoolean(AD_ENABLED, value);
    }

    public void setAdInfo(AdInfoBean adInfo) {
        sharedPreUtils.putString(AD_INFO, GsonUtils.obj2String(adInfo));
    }

    public AdInfoBean getAdInfo() {
        String adInfo = sharedPreUtils.getString(AD_INFO);
        return GsonUtils.string2Obj(adInfo, AdInfoBean.class);
    }

    public String getUmengId(){
        return sharedPreUtils.getString(UMENG_ID);
    }

    public void setUmengId(String umengId){
        sharedPreUtils.putString(UMENG_ID, umengId);
    }

    public void setReadmeInit(boolean inited){
        sharedPreUtils.putBoolean(README_INIT, inited);
    }

    public boolean getReadmeInit(){
        return sharedPreUtils.getBoolean(README_INIT, false);
    }
}
